package com.xiaoKe.zhonghzu.global.tool;

/**
 * @ProjectName : app
 * @Author : Shijingna
 * @Time : 2023/3/17 11:45 上午
 * @Description : 键盘自动收起
 */
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

public class HideIMEUtil {
    public static void wrap(Activity activity) {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        wrap(contentParent);
    }
    public static void wrap(Fragment fragment) {
        ViewGroup contentParent = (ViewGroup) fragment.getView().getParent();
        if (contentParent!=null){
            wrap(contentParent);
        }
    }
    public static void wrap(ViewGroup contentParent) {
        View content = contentParent.getChildAt(0);
        contentParent.removeView(content);
        ViewGroup.LayoutParams p = content.getLayoutParams();
        AutoHideIMEFrameLayout layout = new AutoHideIMEFrameLayout(content.getContext());
        layout.addView(content);
        contentParent.addView(layout, new ViewGroup.LayoutParams(p.width, p.height));
    }
}

